package com.jh.fcsm.beans.area;

import com.alibaba.excel.annotation.ExcelProperty;
import io.swagger.annotations.ApiModelProperty;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import org.apache.ibatis.type.JdbcType;
import tk.mybatis.mapper.annotation.ColumnType;

import javax.persistence.Column;

public class ImportError {
    @ExcelProperty(index = 0)
    @Column(name = "INDEX")
    @ColumnType(jdbcType = JdbcType.INTEGER)
    @ApiModelProperty(value = "序号")
    private Integer index;
    @ExcelProperty(value = "行政区划代码")
    @Column(name = "CODE")
    @ColumnType(jdbcType = JdbcType.VARCHAR)
    @ApiModelProperty(value = "行政区划代码")
    private String code;
    @ExcelProperty(value = "行政区划名称")
    @Column(name = "NAME")
    @ColumnType(jdbcType = JdbcType.VARCHAR)
    @ApiModelProperty(value = "行政区划名称")
    private String name;
    @ExcelProperty(value = "父级区划代码")
    @Column(name = "PARENT_CODE")
    @ColumnType(jdbcType = JdbcType.VARCHAR)
    @ApiModelProperty(value = "父级区划代码")
    private String parentCode;
    @ExcelProperty(value = "错误原因")
    @Column(name = "ERROR_MESSAGE")
    @ColumnType(jdbcType = JdbcType.VARCHAR)
    @ApiModelProperty(value = "错误原因")
    private StringBuilder errorMessage = new StringBuilder();

    public ImportError(Integer index, String code, String name, String parentCode, String errorMessage) {
        this.index = index;
        this.code = code;
        this.name = name;
        this.parentCode = parentCode;
        this.errorMessage.append(errorMessage);
    }

    public void setIndex(Integer index) {
        this.index = index;
    }

    public Integer getIndex() {
        return index;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getCode() {
        return code;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getName() {
        return name;
    }

    public void setParentCode(String parentCode) {
        this.parentCode = parentCode;
    }

    public String getParentCode() {
        return parentCode;
    }

    public String getErrorMessage() {
        return errorMessage.toString();
    }

    public void appendErrorMsg(String newErrorMsg) {
        if (newErrorMsg != null && !newErrorMsg.isEmpty()) {
            if (errorMessage.length() > 0) {
                errorMessage.append("; ");
            }
            errorMessage.append(newErrorMsg);
        }
    }

    @Override
    public String toString() {
        return ToStringBuilder.reflectionToString(this, ToStringStyle.JSON_STYLE);
    }
}
